const errorType = require("../constants/error-type");

const errorHandle = (type, ctx) => {
  let status, message;
  switch (type) {
    case errorType.NAME_OR_EMAIL_OR_PHONE_IS_NOT_NULL:
      status = 400;
      message = "用户基本数据不能为空";
      break;
    case errorType.NAME_ALREADY_EXISTS:
      status = 409;
      message = "用户名已经存在,请更换用户名~";
      break;
    case errorType.EMAIL_ALREADY_EXISTS:
      status = 409;
      message = "邮箱已经存在,请更换邮箱~";
      break;
    case errorType.CELLPHONE_ALREADY_EXISTS:
      status = 409;
      message = "手机号码已经存在,请更换手机号码~";
      break;
    case errorType.USER_NAME_IS_NOT_EXISTS:
      status = 400;
      message = "用户名不存在,请注册帐号~";
      break;
    case errorType.CELLPHONE_IS_NOT_EXISTS:
      status = 400;
      message = "手机号码不存在,请注册帐号~";
      break;
    case errorType.EMAIL_IS_NOT_EXISTS:
      status = 400;
      message = "邮箱不存在,请注册帐号~";
      break;
    case errorType.PASSWORD_IS_INCORRECT:
      status = 400;
      message = "密码不正确,请重新输入密码~~";
      break;
    case errorType.UNAUTHORIZATION:
      status = 401;
      message = "无效token";
      break;
    case errorType.CAPITAL_BASE_VALUE_NOT_NULL:
      status = 400;
      message = "资金基本信息不能为空";
      break;
    case errorType.CAPITAL_DATA_IS_NULL:
      status = 400;
      message = "资金数据为空,请添加内容!";
      break;
    default:
      status = 404;
      message = "NOT FOUND";
      break;
  }
  ctx.status = status;
  ctx.body = message;
};

module.exports = errorHandle;
